package com.example.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ElasticConfig {
    @Value("${es.hostname}")
    public  String hostname;
    //@value注解不能够赋值static静态属性或者静态方法
    @Value("${es.port}")
    public  int port;
    @Value("${es.scheme}")
    public  String scheme;


    //可以使用静态方法，
    @Bean
    public RestHighLevelClient highLevelClient() {

        RestHighLevelClient highLevelClient = new RestHighLevelClient(RestClient.builder(
                new HttpHost(hostname, port, scheme)
        ));
        return highLevelClient;
    }
    //用不用静态没关系，因为就算多个线程调用一个对象的方法或静态方法，只要不是改变属性，就不会you安全问题，或者竞争

//    @Bean
//    public EsDDLComponent esDDLComponent() {
//        return new EsDDLComponent();
//    }
    //private RestHighLevelClient highLevelClient;
}
